package dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import po.EmpHistory;
import po.Rating;
import po.User;

public class HistoryDao extends BaseDAO implements IHistoryDao {
	public List findByHql(String hql) {
		try {
			String queryString = hql;
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {		
			throw re;
		} 
	} 
	
	public Object findUserInfo(int id) {
		
		try {
			Object obj = getSession().find(User.class, id);
			return obj;
		}catch (RuntimeException re) {
			//log.error("find by id failed", re);
			throw re;
		}
	}	
	
	public Object findHisInfo(int id) {
		
		try {
			Object obj = getSession().find(EmpHistory.class, id);
			return obj;
		}catch (RuntimeException re) {
			//log.error("find by id failed", re);
			throw re;
		}
	}	
	
	public void updateRating(Rating rat) {
		Transaction tran = null;
		Session session = null;
		try {
			session = getSession();
			tran = session.beginTransaction();
			session.update(rat);
			tran.commit();
		} catch (RuntimeException re) {
			if(tran != null) tran.rollback();
			throw re;
		} finally {
			session.close();
		}
	}
	
	public void updateHistory(EmpHistory his) {
		Transaction tran = null;
		Session session = null;
		try {
			session = getSession();
			tran = session.beginTransaction();
			session.update(his);
			tran.commit();
		} catch (RuntimeException re) {
			if(tran != null) tran.rollback();
			throw re;
		} finally {
			session.close();
		}
	}
}
